package com.lin.mybatis.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.lin.mybatis.interceptor.CustTenantLineInnerInterceptor;
import com.lin.mybatis.interceptor.TenantHandler;
import com.lin.mybatis.interceptor.TestInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @作者: 林江
 * @创建时间: 2024/4/27
 * @功能:
 */
@Configuration
public class MybatisConfig extends MybatisCommonConfig {
    /**
     * -------------------------------
     * 自定义插件
     * -------------------------------
     *
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = super.mybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new TestInnerInterceptor());

        // 租户插件
        CustTenantLineInnerInterceptor tenantInterceptor = new CustTenantLineInnerInterceptor();
        tenantInterceptor.setTenantLineHandler(new TenantHandler());
        interceptor.addInnerInterceptor(tenantInterceptor);
        return interceptor;
    }
}
